<?php
class BuyorderController extends BuynodeController {
	
	//添加订单 采用了cookie
	public function add() {
		$rs = self::getBuyOrderService ()->addOrder ( $this->_user_global ['uid'], null, $_POST ['remark'] );
		self::getLogService ()->add ( $this->_user_global ['real_name'], $rs ['message'] );
		
		$this->sendNotice ( $rs ['message'], null, $rs ['status'] );
	}
	
	public function order() {
		$order = self::getBuyOrderService ()->getOrderByUid ( $_GET ['p'], $this->_user_global ['uid'] );
		$this->view ()->assign ( 'order', $order ['order'] );
		$this->view ()->assign ( 'num', $order ['page'] );
		
		$this->view ()->display ( "file:buy/order.tpl" );
	}
	
	public function stat() {
		$rs = self::getBuyOrderService ()->stat ();
		$this->view ()->assign ( "rs", $rs );
		$this->view ()->display ( "file:buy/stat.tpl" );
	}
	
	public function search() {
		$order = self::getBuyOrderService ()->search ( $_GET ['key'], $_GET ['value'] );
		$this->view ()->assign ( 'order', $order ['order'] );
		$this->view ()->assign ( 'num', $order ['page'] );
		$this->view ()->assign ( 'status', $order ['status'] );
		$this->view ()->display ( "file:buy/list.tpl" );
	}
	
	public function export() {
		self::getBuyOrderService ()->export ( $_GET ['id'] );
	}
	
	public function remark() {
		$rs = self::getBuyOrderService ()->setOrderRemark ( $_POST ['remark'], $_POST ['orderno'] );
		$this->sendNotice ( $rs ['message'], null, $rs ['status'] );
	}
	
	public function setStatus() {
		$rs = self::getBuyOrderService ()->setStatusBySNO ( $_POST ['status'], $_POST ['orderno'], $this->_user_global );
		self::getLogService ()->add ( $this->_user_global ['real_name'], $rs ['message'] );
		$this->sendNotice ( $rs ['message'], null, $rs ['status'] );
	}
	
	public function listing() {
		$order = self::getBuyOrderService ()->getOrder ( $_GET ['p'], $_GET ['status'] );
		$this->view ()->assign ( 'maxid', $order ['maxid'] );
		$this->view ()->assign ( 'order', $order ['order'] );
		$this->view ()->assign ( 'num', $order ['page'] );
		$this->view ()->assign ( 's', $order ['s'] );
		$this->view ()->assign ( 'status', $order ['status'] );
		$this->view ()->display ( "file:buy/list.tpl" );
	}
	
	//合并
	public function merge() {
		$rs = self::getBuyOrderService ()->merge ( $_POST ['ids'], $this->_user_global );
		self::getLogService ()->add ( $this->_user_global ['real_name'], "合并订单" );
		$this->sendNotice ( $rs ['message'], $rs ['data'], $rs ['status'] );
	}
	//删除产品
	public function del() {
	
	}
	
	public static function getBuyOrderService() {
		return new BuyOrderService ();
	}
}